#pragma once

#include"Common.h"


//单例模式（恶汉）
class CentralCache   
{
public:
	 static CentralCache* GetInstance()
	{
		return &_sInst;     //获取对象
	}

	 //先获取Span
	 Span* GetOneSpan(SpanList& list, size_t size);
	//从Centralcache中获取一定数量的对象给threadcache
	 size_t FetchRangeObj(void*& start, void*& end, size_t n, size_t size);
	//归还一段自由链表给centralcache的span
	 void ReleaseListToSpans(void* start, size_t size);
private:
	SpanList _spanLists[NFREELISTS];       //thread_cache和Central_cache区域的桶结构相同
private:
	CentralCache()              //私有化其构造，拷贝构造函数，避免在其他外部构造对象
	{  }
	CentralCache(const CentralCache&) = delete;       //禁止掉

	static CentralCache _sInst;    //单例恶汉模式，优先创建对象，避免线程安全
};